#########################################################################
#  Erok - Deal object
#  Copyright (c) 2008 Erok Team
#
#  This software is open source, licensed under the GNU General Public
#  License, version 2.
#  Basically, this means that you're allowed to modify and distribute
#  this software. However, if you distribute modified versions, you MUST
#  also distribute the source code.
#  See http://www.gnu.org/licenses/gpl.html for the full license.
#
#  $Revision: 18 $
#  $Id: Deal.py 18 2008-02-25 11:21:16Z malevolyn $
#
#########################################################################
##
# MODULE DESCRIPTION: Deal object
#
# The complete Deal API is implemented here but the logic is in the AI function
#
#
# States:
# request
# incomingDeal
# ready
# finalized
# completed

import Globals
import Utils
import Log
import Network.Send
import time

class Deal:
    def __init__(self,other):
        self.other = other

    def dealPlayer(self):
        messageSender.sendDeal(self.other['ID'])
        self['state'] = 'request'
        ai_v['temp']['deal'] = self

    def incomingDeal(self):
        ai_v['temp']['deal'] = self
        self['state'] = 'incomingDeal'
        if config['dealAuto']:
            self.accept()
            self['state'] = 'accepted'

    def AI():
        # Maybe add the deal logic in here
        # and only call AI if ai_v['temp']['deal']
        # is set
        pass

    def add(self,item,amount):
        messageSender.sendDealAddItem(item-['index'],amount)

    def accept(self,args):
        messageSender.sendDealAccept()

    def cancel(self,args):
        messageSender.sendDealCancel()

    def finalize(self,args):
        if self['state'] == 'engaged': return 0;

    def trade(self,args):
        pass

    def zeny(self,args):
        pass

    def list(self,args):
        pass

